<?php
include_once(__PHY_LIB.'/conf/display.conf.php');
include_once(__PHY_LIB.'/class/I18lText.class.php');
include_once(__PHY_LIB.'/class/I18lUrl.class.php');

function smarty_modifier_lang($sCode, $sMode='text')
{
	static $_I18L;
	$sLang = $_COOKIE['lang'] ? $_COOKIE['lang'] : __DSP_LANG;
	if ('TEXT' == strtoupper($sMode)) {
		if (!is_array($_I18L['TEXT'])) {
			$sPhpCacheFile = __PHY_TMP."/phpcache/i18l_text_{$sLang}.php";
			if (file_exists($sPhpCacheFile) && ($sConfig = trim(file_get_contents($sPhpCacheFile)))
				&& '<?php' == substr($sConfig, 0, 5) && '?>' == substr($sConfig, -2)) {
				eval(substr($sConfig, 5, -2)); // get $_I18L['TEXT']
			}
			else {
				return $sCode;
			}
		}
		return $_I18L['TEXT'][$sCode] ? $_I18L['TEXT'][$sCode] : $sCode;
	}
	elseif ('URL' == strtoupper($sMode)) {
		if (!is_array($_I18L['URL'])) {
			$sPhpCacheFile = __PHY_TMP."/phpcache/i18l_url_{$sLang}.php";
			if (file_exists($sPhpCacheFile) && ($sConfig = trim(file_get_contents($sPhpCacheFile)))
				&& '<?php' == substr($sConfig, 0, 5) && '?>' == substr($sConfig, -2)) {
				eval(substr($sConfig, 5, -2)); // get $_I18L['URL']
			}
			else {
				return $sCode;
			}
		}
		return $_I18L['URL'][$sCode] ? $_I18L['URL'][$sCode] : $sCode;
	}
	else {
	    return $sCode;
	}
}
?>
